﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ELMWCFServiceClass.ELMWCF;
using System.IO;
using System.Windows.Media.Imaging;

namespace ELMApplication.Common.UC
{
    public partial class UserSimpleInfoUC : UserControl
    {
        public UserSimpleInfoUC()
        {
            InitializeComponent();
            
            this.Loaded += new RoutedEventHandler(UserSimpleInfoUC_Loaded);
        }
        public void ShowImg(Human hm2)
        {
            img_EmployeeHead.Source = new BitmapImage(new Uri("user.png",UriKind.RelativeOrAbsolute));
            if (hm2 != null)
            {
                Human hm = hm2;
                var query = from q in hm.Attributes where q.Key.FieldId == new Guid("9dc96c72-154c-4e87-bdcb-89d0be5bc795") select q;
                if (query.Count() == 1)
                {
                    if (!string.IsNullOrEmpty(query.First().Value) && query.First().Value != Guid.Empty.ToString())
                    {
                        ELMServiceClient _domainClient = new ELMServiceClient();
                        _domainClient.GetRecourceAsync(new Guid(query.First().Value));
                        _domainClient.GetRecourceCompleted += (sender1, e1) =>
                        {
                            if (e1.Error == null && e1.Result != null)
                            {
                                MemoryStream ms = new MemoryStream(e1.Result.FileData);
                                BitmapImage bmp = new BitmapImage();
                                bmp.SetSource(ms);
                                img_EmployeeHead.Source = bmp;
                            }
                        };
                    }
                }
            }
        }
        void UserSimpleInfoUC_Loaded(object sender, RoutedEventArgs e)
        {
          
        }

        
    }
}
